package cn.lasse.springframework.aop.impl;

import cn.lasse.springframework.aop.IUserService;
import cn.lasse.springframework.bean.UserDao;
import cn.lasse.springframework.beans.factory.annotation.Autowired;
import cn.lasse.springframework.beans.factory.annotation.Value;
import cn.lasse.springframework.stereotype.Component;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Random;

@Component
@ToString
public class UserServiceImpl implements IUserService {
    @Getter
    @Setter
    private String token;

    @Value("${dynamicValue}")
    private String dynamicValue;

    @Autowired
    private UserDao userDao;

    @Override
    public String queryUserInfo() {
        try {
            System.out.println("我是函数：queryUserInfo()");
            Thread.sleep(new Random(1).nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "穗爷，007，广州"+token;
    }

    @Override
    public String register(String userName) {
        try {
            System.out.println("我是函数：register()");
            Thread.sleep(new Random(1).nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "注册用户：" + userName + " success！";
    }

    @Override
    public String queryUserNameById(String uid) {
        try {
            Thread.sleep(new Random(1).nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String name = userDao.queryUserNameById("10001");
        return name + "，" + dynamicValue;
    }
}
